home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 768 < prev    next >
Internet Message Format  |  1996-08-06  |  2KB

  1. Path: xylogics.com!not-for-mail
  2. From: carlson@xylogics.com (James Carlson)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Q: char **foo, char *foo[], and char foo[][] ?
  5. Date: 19 Apr 1996 08:20:11 -0400
  6. Organization: Xylogics Incorporated
  7. Distribution: world
  8. Message-ID: <4l80dr$q6@newhub.xylogics.com>
  9. References: <4l33ok$oo2@Sherlock.lectra.fr> <KANZE.96Apr18105949@gabi.gabi-soft.fr>
  10. Reply-To: carlson@xylogics.com
  11. NNTP-Posting-Host: newhub.xylogics.com
  12.  
  13.  
  14. In article <KANZE.96Apr18105949@gabi.gabi-soft.fr>, kanze@gabi-soft.fr (J. Kanze) writes:
  15. |> In article <4l33ok$oo2@Sherlock.lectra.fr> phil@rd.lectra.fr (Philippe
  16. |> Maurisset) writes:
  17. [...]
  18. |> 
  19. |> |> myexample()
  20. |> |> {
  21. |> |>     char foo[MAX_X][MAX_Y];
  22. |> |>     ...
  23. |> |>     myfunc( (char **)foo );
  24. |> |> }
  25. |> 
  26. |> |> void myfunc( char *foo[MAX_X] )
  27. |>                 ^^^^^^^^^^^^^^^^
  28. |> 
  29. |> Because it appears as a function parameter, this is actually a
  30. |> declaration of a char**, and not a char*[].
  31.  
  32. True.
  33.  
  34. |> So in fact, you have no type incompatibility to deal with.
  35.  
  36. Not true.  The original definition of foo in myexample() was as a two-
  37. dimensional array, which, in C, is implemented in storage as a
  38. unidimensional array of size MAX_X*MAX_Y*sizeof(char), not as an array
  39. of pointers-to-characters.  If you try to access this as a pointer-to-a-
  40. pointer, you will be attempting to dereference character data as a
  41. pointer.  (If you've got a real operating system, then this just results
  42. in a core fault.  If you're running on a toy, the results could be far
  43. worse.)
  44.  
  45. (Of course, the type of the formal argument is compatible with the
  46. cast given in the call, but the cast itself is bogus.)
  47.  
  48. -- 
  49. James Carlson <carlson@xylogics.com>            Tel:  +1 617 272 8140
  50. Annex Interface Development / Xylogics, Inc.          +1 800 225 3317
  51. 53 Third Avenue / Burlington MA  01803-4491     Fax:  +1 617 272 2618
  52.